<template>
  <div>
    <el-header>
      <span class="logo">夕语管理后台v1.0</span>
      <span class="msg">欢迎您-Admin<em @click="loginOut">【退出登录】</em></span>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <div :class="currentPath === 'articleList' ? 'm-active' : ''" class="m-i" @click="to('management/articleList')"><span>文章列表</span><i class="el-icon-arrow-right"></i></div>
        <div :class="currentPath === 'publish' ? 'm-active' : ''" class="m-i" @click="to('management/publish')"><span>发布文章</span><i class="el-icon-arrow-right"></i></div>
      </el-aside>
      <el-main v-loading="isLoading">
        <router-view @table-loading-open="loading" @table-loading-close="loading" />
      </el-main>
    </el-container>
  </div>
</template>
<script>
  export default {
    name: 'management',
    methods: {
      to (name) {
        this.$router.push(`/${name}`)
      },
      loginOut () {
        this.$alert('是否确认退出登录？', '退出登录', {
          type: 'warning',
          callback: e => {
            if (e === 'confirm') {
              this.$message({
                type: 'success',
                message: '退出成功！'
              })
              sessionStorage.removeItem('token')
              this.$router.push('/login')
            }
          }
        })
      },
      loading (status) {
        this.isLoading = status
      }
    },
    data () {
      return {
        currentPath: '',
        isLoading: false
      }
    },
    watch: {
      $route (router) {
        this.currentPath = router.name
      }
    },
    created() {
      this.currentPath = this.$router.history.current.name
    }
  }
</script>
<style>
  * {
    margin: 0;
    padding: 0;
  }
  .el-header {
    background-color: #fff;
    text-align: left;
    height: 60px;
    line-height: 60px;
    position: relative;
    z-index: 1;
    padding: 0 14px;
    box-sizing: border-box;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
  }
  .el-header .logo {
    color: #008eff;
    font-weight: bold;
    font-size: 22px;
    font-family: cursive;
  }
  .el-header .msg {
    font-size: 14px;
    color: #666;
  }
  .el-header .msg em {
    font-style: normal;
    padding-left: 4px;
    cursor: pointer;
    color: #000;
  }
  .el-header .msg em:hover{
    color: #409EFF;
    text-decoration: underline;
  }

  .el-aside {
    background-color: #fff;
    color: #444;
    text-align: center;
    height: 100%;
    border-right: 1px solid #ddd;
  }

  .el-container {
    background-color: #fff;
    color: #333;
    position: absolute;
    box-sizing: border-box;
    padding-top: 60px;
    height: 100%;
    left: 0;
    top: 0;
    width: 100%;
  }
  .m-i {
    color: #444;
    display: flex;
    padding: 0 14px;
    justify-content: space-between;
    align-items: center;
    height: 42px;
    line-height: 42px;
    font-size: 14px;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    transition: all .133s linear;
  }
  .m-active,.m-i:hover{
    background: #f2f9ff;
    color: #008eff;
  }
  .el-main {
    min-width: 1080px;
  }
</style>